<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dung
 * Date: 2/26/14
 * Time: 1:20 PM
 * To change this template use File | Settings | File Templates.
 */
?>
<?php
if(isset($_SESSION["users_id"]) && $_SESSION["group_id"]==1){
    $id=$_GET['information_id'];
    $information=InformationDetail($id);
    $row_information=mysql_fetch_array($information);
    if(isset($_POST["btnEdit"]))
    {
        $name=$_POST["name"];
        $content=$_POST["Content"];
        $language_id=$_POST["language"];settype($language_id,"int");
        $show=$_POST['show'];settype($show,"int");
        EditInformation($id,$name,$content,$language_id,$show);
        header("location:index.php?p=informationlist");
    }
    ?>
<form id="maincp" name="form1" method="post" action="">
    <h1 class="h1">Edit Information</h1>
    <p>Please complete all form below to add a new information.</p>
    <ul class="list2">
        <li><h3>Title</h3></li>
        <li><input value="<?php echo $row_information['key']; ?>" class="input" type="text" name="name" id="name" /></li>
        <li><h3>Content</h3></li>
        <li><textarea class="ckeditor" name="Content" id="Content" cols="60" rows="5"><?php echo $row_information['value']; ?></textarea></li>
        <li>
            <fieldset>
                <legend><h3>Display</h3></legend>
                <p>Choose where to display contents.</p>
                <select id="group" name="group" style="width: 100px">
                    <?php if($row_information['group']=='home_page') { ?>
                        <option selected="selected" value="home_page">Home Page</option>
                        <option value="info">Info</option>
                        <option value="footer">Footer</option>
                    <?php }elseif($row_information['group']=='info'){ ?>
                        <option value="home_page">Home Page</option>
                        <option selected="selected" value="info">Info</option>
                        <option value="footer">Footer</option>
                    <?php }else{ ?>
                        <option value="home_page">Home Page</option>
                        <option value="info">Info</option>
                        <option selected="selected" value="footer">Footer</option>
                    <?php }?>
                </select>
            </fieldset>
        </li>
        <li>
            <fieldset>
                <legend><h3>Language</h3></legend>
                <p>Choose contents language.</p>
                <select id="language" name="language" style="width: 100px">
                    <?php
                    $language=LanguageList();
                    while($row_language=mysql_fetch_array($language)){ ?>
                        <?php if($row_information['language_id']==$row_language['language_id']) { ?>
                        <option selected="selected" value="<?php echo $row_language['language_id']; ?>"><?php echo $row_language['name']; ?></option>
                    <?php } else { ?>
                        <option value="<?php echo $row_language['language_id']; ?>"><?php echo $row_language['name']; ?></option>
                    <?php } ?>
                    <?php } ?>
                </select>
            </fieldset>
        </li>
        <li><input class="button editinformation" type="submit" name="btnEdit" id="btnEdit" value="Edit Information" /></li>
    </ul>
    <a href="index.php?p=informationlist" title="Back to Dashboard">&laquo; Back to Dashboard.</a>
</form>

<script type="text/javascript">
    function BrowseServer(startupPath, functionData) {
        var finder = new CKFinder();
        finder.basePath = 'js/ckfinder/';
        //???ng path n?i ??t ckfinder
        finder.startupPath = startupPath;
        //???ng path hi?n s?n cho user ch?n file
        finder.selectActionFunction = SetFileField;
        // hàm s? ???c g?i khi 1 file ???c ch?n
        finder.selectActionData = functionData;
        //id c?a text field c?n hi?n ??a ch? hình
        //finder.selectThumbnailActionFunction = ShowThumbnails; //hàm s? ???c g?i khi 1 file thumnail ???c ch?n
        finder.popup();
        // B?t c?a s? CKFinder
    }//BrowseServer

    function SetFileField(fileUrl, data) {
        document.getElementById(data["selectActionData"]).value = fileUrl;
    }

    function ShowThumbnails(fileUrl, data) {
        var sFileName = this.getSelectedFile().name;
        // this = CKFinderAPI
        document.getElementById('thumbnails').innerHTML += '<div class="thumb">' + '<img src="' + fileUrl + '" />' + '<div class="caption">' + '<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' + '</div>' + '</div>';
        document.getElementById('preview').style.display = "";
        return false;
        // n?u là true thì ckfinder s? t? ?óng l?i khi 1 file thumnail ???c ch?n
    }
</script>
<?php
}else{
    header("location:index.php?p=logincp");
}
?>